package com.palnar.ilecker.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.ksoap2.serialization.SoapObject;

import com.palnar.ilecker.utils.XmlDocumentUtility;

public class SpecificationGroup extends ItemBase implements Serializable
{
	private Integer clientId;
	private Integer serverId;
	
	private String code;
	private Integer hotelId;
	private List<SpecificationMember> specificationMembers;
	
	public SpecificationGroup()
	{
		this.specificationMembers = new ArrayList<SpecificationMember>();
	}
	
	public SpecificationGroup(String name)
	{
		this.specificationMembers = new ArrayList<SpecificationMember>();
		//this.name=name;
	}

//	public String getName() 
//	{
//		return this.name;
//	}
	
	public String getCode() 
	{
		return this.code;
	}
	
	public int getClientId()
	{
		return this.clientId;
	}
	
	public int getServerId()
	{
		return this.serverId;
	}
	
	public List<SpecificationMember> getSpecificationMembers()
	{
		return this.specificationMembers;
	}

	 public Integer getHotelId()
	 {
		 return this.hotelId;
	 }

	public void setClientId(int id)
	{	
		this.clientId =id;
	}
	
	public void setServerId(int id)
	{	
		this.serverId =id;
	}

//	public void setName(String name)
//	{ 
//		this.name = name;
//	}
	
	public void setCode(String code)
	{ 
		this.code = code;
	}
	
	 public void setHotelId(Integer hotelId)
	 {
		 this.hotelId = hotelId;
	 }	
	
	public void SetSpecificationMembers(List<SpecificationMember> specMembers)
	{
		for (SpecificationMember specificationMember : specMembers) 
		{
			this.specificationMembers.add(specificationMember);
		}
	}
	
	public SpecificationMember TryGetSpecificationMember(Integer memberId)
	{
		if(!this.specificationMembers.isEmpty())
		{
			for (SpecificationMember specMember : this.specificationMembers) 
			{
				if(specMember.getClientId() == memberId)
				{
					return specMember;
				}
			}
		}
		return  null; 
	}
	
	public static SpecificationGroup SpecificationGroupBuilder(SoapObject specGroupSoapObj, HashMap<Integer, Language> languages) 
	{
		SpecificationGroup specficationGroup = new SpecificationGroup(null);
		specficationGroup.serverId = Integer.parseInt(specGroupSoapObj.getProperty("Id").toString());
		specficationGroup.setName(Integer.parseInt(specGroupSoapObj.getProperty("Name").toString()));
		Object codeObj = specGroupSoapObj.getProperty("Code");
		if(codeObj != null)
		{
			if (!codeObj.toString().equals(XmlDocumentUtility.nullString))
			{
				specficationGroup.code = codeObj.toString();
			}
		}
		List<SpecificationMember> specificationMemberList = new ArrayList<SpecificationMember>();		
//		SoapObject specificationDetailsNameSoapObject = (SoapObject)specGroupSoapObj.getProperty("DisplayNames");
//		specficationGroup.TextNameBuilder(specificationDetailsNameSoapObject, languages);

		SoapObject specificationMembersSoapObject =(SoapObject) specGroupSoapObj.getProperty("Children");
		for (int i = 0; i < specificationMembersSoapObject.getPropertyCount(); i++) 
		{
			SpecificationMember specificationMember = new SpecificationMember();
			SoapObject specMemberSoapObject =(SoapObject)specificationMembersSoapObject.getProperty(i);
			
			specificationMember = SpecificationMember.SpecificationMemberBuilder(specMemberSoapObject, languages);			
			specificationMemberList.add(specificationMember);	
		}
		specficationGroup.specificationMembers = specificationMemberList;
		return specficationGroup;
	}
}
